package com.kakarote.job.hrm;

import cn.hutool.core.thread.ThreadUtil;
import com.kakarote.core.utils.UserUtil;
import com.kakarote.hrm.feign.service.HrmService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutorService;

@Component
@Slf4j
public class AttendanceGroupJob {

    @Autowired
    private HrmService hrmService;

    private static final ExecutorService EXECUTOR = ThreadUtil.newExecutor(10, 10, 65536);

    @XxlJob("AttendanceGroupJob")
    public ReturnT<String> attendanceGroupJobHandler(String param) {
        //查询出人资里面的使用考勤公司Id列表（设置了Wifi和定位）
        try {
            EXECUTOR.execute(() -> {
                hrmService.changeAttendanceGroup();
                XxlJobLogger.log("结束执行");
            });
        } catch (Exception ex) {
            log.error("执行错误", ex);
        } finally {
            UserUtil.removeUser();
        }
        XxlJobLogger.log("人资定时变更考勤组执行完成");
        return ReturnT.SUCCESS;
    }
}
